package com.ww.springboot.boot.baseTest.运算符;

import com.ww.springboot.boot.util.HexUtil;

/**
 * 描述：运算符
 *
 * @author 🧑 ‍wanwei
 * @since 2022-02-25 16:38
 */
public class operatorDemo {

    //16进制
    private static final Integer a = 0x00000001;
    private static final Integer b = 0x00000010;
    private static final Integer c = 0x00000011;
    private static final Integer d = 0x00000100;
    private static final Integer e = 0x00000101;
    private static final Integer f = 0x00000110;
    private static final Integer g = 0x00000111;
    private static final Integer h = 0x00001000;

    public static void main(String[] args) {
        //或
        println(a | b);
        //且
        println(a & b);
        //异或
        println(a ^ b);
        println(a ^ c);

        //非 即把0变为1 1变为0
        System.out.println(~a);
        System.out.println(0xFFFFFFFE);


        // >> >>>的区别 >>无符号右移 正数负数都相当于正常除4   >>>带符号右移  符号识别为最高位1并参与运算
        System.out.println(h);
        System.out.println(-h);
        System.out.println(0xFFFFF000);
        System.out.println(-h >> 2);
        System.out.println(-h >>> 2);
        System.out.println(0x3FFFFC00);
        //没有<<< 正常计算使用>> <<  散列函数一般使用<<< 因为对散列函数来说 不需要区分数字的正负 只是视为进制数
        System.out.println(-h << 2);
        System.out.println(h << 2);


    }


    private static void println(Integer i) {
        System.out.println(HexUtil.hexChange(Long.valueOf(i), 16));
    }
}
